package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.bean.DataBean;
import com.bw.service.DataBeanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author admin
 * @date 2025年09月29日 09:36
 */
@RestController
public class DataBeanController {
    @Autowired
    private DataBeanService dataBeanService;

    @RequestMapping("/s1")
    public JSONObject select1(){
        JSONObject realer = new JSONObject();
        realer.put("status",0);
        realer.put("msg","");
        List<DataBean> beans = dataBeanService.select1();
        for (DataBean bean : beans) {
            realer.put("data",bean.getCta());
        }
        return realer;
    }

    @RequestMapping("/s2")
    public JSONObject select2(){
        JSONObject realer = new JSONObject();
        realer.put("status",0);
        realer.put("msg","");

        JSONObject data = new JSONObject();
        realer.put("data",data);

        JSONArray mapData = new JSONArray();
        data.put("mapData",mapData);
        realer.put("valueName","总成交额");

        List<DataBean> beans = dataBeanService.select3();
        for (DataBean bean : beans) {
            JSONObject row = new JSONObject();
            row.put("name",bean.getName()) ;
            row.put("value",bean.getCta()) ;
            mapData.add(row);
        }
        return realer;
    }

    @RequestMapping("/s3")
    public JSONObject select3(){
        JSONObject realer = new JSONObject();
        realer.put("status",0);
        realer.put("msg","");

        JSONObject data = new JSONObject();
        realer.put("data",data);

        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();
        data.put("columns",columns);
        data.put("rows",rows);

        JSONObject co1 = new JSONObject();
        co1.put("name","名称");
        co1.put("id","name");
        columns.add(co1);

        JSONObject co2 = new JSONObject();
        co2.put("name","订单金额");
        co2.put("id","cta");
        columns.add(co2);

        List<DataBean> beans = dataBeanService.select4();
        for (DataBean bean : beans) {
            JSONObject row = new JSONObject();
            row.put("name",bean.getName()) ;
            row.put("cta",bean.getCta());
            rows.add(row);

        }
        return realer;
    }

    @RequestMapping("/s4")
    public JSONObject select4(){
        JSONObject realer = new JSONObject();
        realer.put("status",0);
        realer.put("msg","");

        JSONObject data = new JSONObject();
        realer.put("data",data);

        JSONArray categories = new JSONArray();
        JSONArray series = new JSONArray();
        data.put("categories",categories);
        data.put("series",series);

        JSONObject se1 = new JSONObject();
        se1.put("name","交易额");
        JSONArray dataArray = new JSONArray();
        se1.put("data",dataArray);
        series.add(se1);

        List<DataBean> beans = dataBeanService.select6();
        for (DataBean bean : beans) {
        categories.add(bean.getName());
        dataArray.add(bean.getCta());
        }
        return realer;
    }

}
